<template>
  <div>
    <el-dialog title="编辑" v-model="visible" width="1080px" draggable>
      <el-form ref="formRef" :model="formData" label-position="right" label-width="100px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="群名手机号" prop="chargeFlag" required>
              <el-select v-model="formData.chargeFlag" placeholder="请选择" :disabled="!addFlag">
                <el-option v-for="item in phoneList" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="处理人" prop="handleUser" required>
              <el-select v-model="formData.handleUser" filterable placeholder="请选择" clearable>
                <el-option v-for="item in userList" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户类型" prop="userType">
              <el-select v-model="formData.userType" filterable placeholder="请选择" clearable>
                <el-option v-for="item in getEnumBySn('userType')" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="接单日期" prop="receiveDate">
              <el-date-picker value-format="YYYY-MM-DD" v-model="formData.receiveDate"
                              type="datetime"
                              placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="处理状态" prop="handleStatus">
              <el-select v-model="formData.handleStatus" placeholder="请选择">
                <el-option v-for="item in getEnumBySn('handleStatusEnum')" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合作编号" prop="indexId">
              <el-select v-model="formData.indexId" filterable placeholder="请选择">
                <el-option v-for="item in agentList" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户姓名" prop="customName">
              <el-input v-model="formData.customName" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option v-for="item in getEnumBySn('sexEnum')" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预留手机号" prop="reservePhone">
              <el-input v-model="formData.reservePhone" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="处理平台" prop="handlePlatform">
              <el-input v-model="formData.handlePlatform" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="冻结类型" prop="freezeType">
              <el-input v-model="formData.freezeType" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请时间" prop="applyTime">
              <el-date-picker value-format="YYYY-MM-DD" v-model="formData.applyTime"
                              placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="提示方式" prop="promptMode">
              <el-input v-model="formData.promptMode" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否转让" prop="transferFlag">
              <el-select v-model="formData.transferFlag" placeholder="请选择" clearable>
                <el-option v-for="item in getEnumBySn('transferFlag')" :label="item.label" :key="item.value"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="案号" prop="caseNo">
              <el-input v-model="formData.caseNo" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请人" prop="applyUser">
              <el-input v-model="formData.applyUser" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="法院名称" prop="courtName">
              <el-input v-model="formData.courtName" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="法院电话" prop="countPhone">
              <el-input v-model="formData.countPhone" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="收件人" prop="receiveUser">
              <el-input v-model="formData.receiveUser" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否写信" prop="letterFlag">
              <el-input v-model="formData.letterFlag" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="邮寄时间" prop="mailDate">
              <el-date-picker value-format="YYYY-MM-DD" v-model="formData.mailDate"
                              placeholder="选择日期时间"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进线手机号" prop="comePhone" required>
              <el-input v-model="formData.comePhone" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="最新处理情况" prop="handelProcess">
              <el-input v-model="formData.handelProcess" placeholder="请选择">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="贴纸备注" prop="stickerMemo" required>
              <el-input type="textarea" rows="10" v-model="formData.stickerMemo"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="visible = false">取 消</el-button>
          <el-button type="primary" @click="submit" :loading="submitLoading">确 定</el-button>
        </span>
      </template>

    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import {getEnumBySn, getIndexIdList, getPhoneList, getUserList} from "@/api/enums";
const visible = ref(false)
const formRef = ref()
const formData = ref({})
const props = defineProps({
  currentItem: {
    type: Object,
    required: true,
  },
});
import request from '@/config/axios'
const emit = defineEmits(["ok"])

const userList  = ref([])
const agentList = ref([])
const phoneList = ref([])
const submitLoading = ref(false)

onMounted(() => {
  getUserList().then(res => {
    userList.value = res
  })
  getIndexIdList().then(res => {
    agentList.value = res
  })
  getPhoneList().then(res => {
    phoneList.value = res
  })
});

// 保存
const submit = function () {
  if (formData.value.id) {
    edit()
  } else {
    add()
  }
}

//新增
const add = function () {
  submitLoading.value = true
  request.post({
    url: '/thawInfo/save',
    data: formData.value
  }).then(res => {
    visible.value = false
    emit("ok")
  }).finally(() => {
    submitLoading.value = false
  })
}

//编辑
const edit = function () {
  submitLoading.value = true
  request.post({
    url: '/thawInfo/updateById',
    data: formData.value
  }).then(res => {
    visible.value = false
    emit("ok")
  }).finally(() => {
    submitLoading.value = false
  })
}


defineExpose({
  add: (rowData) => {
    visible.value = true
    formData.value = {}
  },
  edit: (rowData) => {
    visible.value = true
    formData.value = rowData
  }
})
</script>


<style scoped></style>
